﻿
package com.ostrich.manpower.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.base.util.HtmlUtil;
import com.base.web.BaseAction;
import com.ostrich.manpower.bean.TostHrDepartinfo;
import com.ostrich.manpower.service.impl.TostHrDepartinfoService;

/**
 * ClassName: Controller <br/>
 * date: 2013-5-9 下午03:07:38 <br/>
 * 
 * @author wangyinan
 * @version
 */
@Controller
@RequestMapping("/tostHrDepartinfo")
public class TostHrDepartinfoController extends BaseAction
{
	private final static Logger log= Logger.getLogger(TostHrDepartinfoController.class);

	// Servrice start
	@Autowired(required=false) //自动注入，不需要生成set方法了，required=false表示没有实现类，也不会报错。
	private TostHrDepartinfoService<TostHrDepartinfo> tostHrDepartinfoService; 

	/**
	 * ilook 首页
	 * @param url
	 * @param classifyId
	 * @return
	 */
	@RequestMapping("/list") 
	public ModelAndView  list(TostHrDepartinfo tostHrDepartinfo,HttpServletRequest request) throws Exception{
		Map<String,Object>  context = getRootMap();
		List<TostHrDepartinfo> dataList = tostHrDepartinfoService.queryByList(tostHrDepartinfo);
		//设置页面数据
		context.put("dataList", dataList);
		return forword("manpower/tabTostHrDepartinfo",context); 
	}
	
	/**
	 * json 列表页面
	 * @param url
	 * @param classifyId
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping("/dataList") 
	public void  dataList(TostHrDepartinfo tostHrDepartinfo,HttpServletResponse response) throws Exception{
		List<TostHrDepartinfo> dataList = tostHrDepartinfoService.queryByList(tostHrDepartinfo);
		//设置页面数据
		Map<String,Object> jsonMap = new HashMap<String,Object>();
		jsonMap.put("total",tostHrDepartinfo.getPager().getRowCount());
		jsonMap.put("rows", dataList);
		HtmlUtil.writerJson(response, jsonMap);
	}
	/**
	 * 添加或修改数据
	 * @param url
	 * @param classifyId
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping("/save")//ModelAndView
	public ModelAndView  save(HttpServletRequest request,TostHrDepartinfo bean,HttpServletResponse response) throws Exception{
		Map<String, Object> context = getRootMap();
		if(bean.getId().equals("")){
			tostHrDepartinfoService.addDept(bean);
			request.setAttribute("success", "您已经添加成功请查看!");
			request.setAttribute("msg", "您已经添加成功请查看。");
			request.setAttribute("url", request.getContextPath()
					+ "/tostHrDepartinfo/list.do");
		}else{
			tostHrDepartinfoService.update(bean);
			request.setAttribute("success", "您已经添加成功请查看!");
			request.setAttribute("msg", "更新成功！");
			request.setAttribute("url", request.getContextPath()
					+ "/tostHrDepartinfo/list.do");
		}
		return forword("penmsg", context);
		
	}
	
	@RequestMapping("/getId")
	public void getId(String id,HttpServletRequest request,HttpServletResponse response) throws Exception{
		Map<String,Object>  context = getRootMap();
		TostHrDepartinfo bean  = tostHrDepartinfoService.queryById(id);
		if(bean  == null){
			sendFailureMessage(response, "没有找到对应的记录!");
			return;
		}
		context.put(SUCCESS, true);
		context.put("data", bean);
		request.setAttribute("boolean","true");
		HtmlUtil.writerJson(response, context);
	}
	
	@RequestMapping("/delete")
	public void delete(String[] id,HttpServletResponse response) throws Exception{
		tostHrDepartinfoService.delete(id);
		sendSuccessMessage(response, "删除成功");
	}
	
	//修改数据类型
	@RequestMapping("/getDepartInfo")
	public void queryDpeartPId(HttpServletResponse response){
		List<TostHrDepartinfo> dataList = tostHrDepartinfoService.queryDapart();
		//设置页面数据
		Map<String,Object> jsonMap = new HashMap<String,Object>();
		jsonMap.put("total",(dataList.size()==0)?0:dataList.size());
		jsonMap.put("data", dataList);
		HtmlUtil.writerJson(response, jsonMap);
	}
	
	@RequestMapping("/getDepartBypost")
	public void getDepartBypost(HttpServletResponse response){
		List<TostHrDepartinfo> dataList = tostHrDepartinfoService.queryDapart();
		HtmlUtil.writerJson(response, dataList);
	}
	
}
